home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / hardware / rap / play.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  2.9 KB  |  121 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include <stdio.h>
  18. #include <fcntl.h>
  19. #include <string.h>
  20. #include <errno.h>
  21. #include <sys/types.h>
  22. #include <signal.h>
  23. #include "rap.h"    
  24. /*    
  25.  *    record.c
  26.  *
  27.  *    This program plays song from a previuosly recorded file
  28.  *    using RAP-10 board. 
  29.  *
  30.  */
  31.  
  32. #define    BUF_SIZE    4096
  33. #define    FILE_HDR    "RAP-10 WAVE FILE"
  34. #define    RAP_FILE    "/dev/rap"
  35. #define    MAX_BUF     10 
  36. #define    FOREVER     for(;;)
  37.  
  38. uchar_t    buf[BUF_SIZE];
  39. uchar_t    *fname;
  40. void       endProg( int );
  41.  
  42. main (int argc, char **argv)
  43. {
  44.  
  45.     register int    fd, rapfd, bytes;
  46.  
  47.     if ( argc <= 1 ) {
  48.         printf ("play: Usage: play <file_name>\n");
  49.         exit(0);
  50.     }
  51.  
  52.     fname = argv[1];
  53.         printf ("play: opening file %s\n", fname); 
  54.         fd = open (fname, O_RDONLY);
  55.         if ( fd == -1 ) {
  56.                 printf ("play: Cannot create file, errno = %d\n", errno);
  57.                 close(rapfd);
  58.                 exit(0);
  59.         }
  60.  
  61.         printf ("play: Checking RAP-10 File ID\n"); 
  62.         if ( read(fd, buf, strlen(FILE_HDR)) <= 0 ) {
  63.                 printf ("play: Could not read the file ID, errno = %d\n",
  64.                 errno);
  65.                 close(fd);
  66.                 exit(0);
  67.         }
  68.     if ( strcmp(buf, FILE_HDR) ) {
  69.         printf ("play: File is not a RAP file\n");
  70.         close(fd);
  71.         exit(0);
  72.     }
  73.  
  74.     printf ("play: opening RAP card\n");
  75.     rapfd = open (RAP_FILE, O_WRONLY);
  76.     if ( rapfd <= 0 ) {
  77.         printf ("play: Cannot open RAP card, errno = %d\n",
  78.         errno);
  79.         exit(0);
  80.     }
  81.  
  82.  
  83.     printf ("play: Playing ..please wait\n");      
  84.  
  85.     /*   ignore Interrupt   */
  86.     sigset (SIGINT, SIG_IGN ); 
  87.  
  88.         FOREVER {          
  89.               bytes = read(fd, buf, BUF_SIZE);  
  90.         if ( bytes < 0 ) {
  91.             printf ("play: error reading data, errno = %d",
  92.                 errno);
  93.             close(fd);
  94.             close(rapfd);
  95.             exit(0);
  96.         }
  97.  
  98.         if ( bytes == 0 )
  99.             break;
  100.  
  101.         bytes = write(rapfd, buf, BUF_SIZE);
  102.         if ( bytes <= 0 ) {
  103.             printf ("play: Cannot read from RAP, errno = %d\n",
  104.             errno);
  105.             close (rapfd);
  106.             close (fd);
  107.             exit(0);
  108.         }
  109.  
  110.     }
  111.     printf ("play: waiting for Play to End\n");
  112.     if ( ioctl (rapfd, RAPIOCTL_END_PLAY) ) {
  113.            printf ("play: Ioctl error %d", errno );
  114.     }
  115.     else printf ("play: Song succesfully played\n");
  116.     close(rapfd);
  117.     close (fd);
  118.  
  119. }
  120.  
  121.